package com.mdd.admin.controller.jiaz;

import com.mdd.admin.aop.Log;
import com.mdd.admin.service.jiaz.ITimeSlotService;
import com.mdd.admin.validate.commons.IdValidate;
import com.mdd.admin.validate.commons.PageValidate;
import com.mdd.admin.validate.setting.SettingWebsiteValidate;
import com.mdd.admin.vo.setting.SettingWebsiteVo;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.core.PageResult;
import com.mdd.common.validate.timeslot.TimeSlotCreateValidate;
import com.mdd.common.validate.timeslot.TimeSlotSearchValidate;
import com.mdd.common.validate.timeslot.TimeSlotUpdateValidate;
import com.mdd.common.validator.annotation.IDMust;
import com.mdd.common.vo.timeslot.TimeSlotDetailVo;
import com.mdd.common.vo.timeslot.TimeSlotListedVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("api/slot")
@Api(tags = "时间段管理")
public class TimeSlotController {

    @Resource
    ITimeSlotService iTimeSlotService;

    @GetMapping("/list")
    @ApiOperation(value = "时间段列表")
    public AjaxResult<PageResult<TimeSlotListedVo>> list(@Validated PageValidate pageValidate, @Validated TimeSlotSearchValidate searchValidate) {
        PageResult<TimeSlotListedVo> list = iTimeSlotService.list(pageValidate, searchValidate);
        return AjaxResult.success(list);
    }

    @GetMapping("/detail")
    @ApiOperation(value = "时间段详情")
    public AjaxResult<TimeSlotDetailVo> detail(@Validated @IDMust() @RequestParam("id") Integer id) {
        TimeSlotDetailVo detail = iTimeSlotService.detail(id);
        return AjaxResult.success(detail);
    }

    @Log(title = "时间段新增")
    @PostMapping("/add")
    @ApiOperation(value = "时间段新增")
    public AjaxResult<Object> add(@Validated @RequestBody TimeSlotCreateValidate createValidate) {
        iTimeSlotService.add(createValidate);
        return AjaxResult.success();
    }

    @Log(title = "时间段编辑")
    @PostMapping("/edit")
    @ApiOperation(value = "时间段编辑")
    public AjaxResult<Object> edit(@Validated @RequestBody TimeSlotUpdateValidate updateValidate) {
        iTimeSlotService.edit(updateValidate);
        return AjaxResult.success();
    }

    @Log(title = "时间段删除")
    @PostMapping("/del")
    @ApiOperation(value = "时间段删除")
    public AjaxResult<Object> del(@Validated @RequestBody IdValidate idValidate) {
        iTimeSlotService.del(idValidate.getId());
        return AjaxResult.success();
    }

    @GetMapping("/getDaySet")
    @ApiOperation(value = "获取预约日期")
    public AjaxResult<SettingWebsiteVo> detail() {
        SettingWebsiteVo detail = iTimeSlotService.detail();
        return AjaxResult.success(detail);
    }

    @Log(title = "设置预约日期")
    @PostMapping("/saveDay")
    @ApiOperation(value = "设置预约日期")
    public AjaxResult<Object> save(@Validated @RequestBody SettingWebsiteValidate websiteValidate) {
        iTimeSlotService.saveTimeSlotDay(websiteValidate);
        return AjaxResult.success();
    }

}
